;(function(){
    // 获取元素; 
    var sign_btn = document.getElementById("login-btn");
    var username_ipt = document.querySelector(".phone-put");
    var password_ipt = document.querySelector(".password-put")
    // 给 sign_btn 绑定事件 : 
    // 发起一个xhr请求; 
    sign_btn.onclick = function(){
       
        xhr({
            url : "http://127.0.0.1/iqiyi/project/src/javascripts/login.php",
            data : {
                username : username_ipt.value,
                password : password_ipt.value
            },
            type : "POST",
            callback : function( res ){

                // 把res字符串转换成对象; 
                res = JSON.parse(res);

                if( res.type === "success"){
                    alert("登录成功，稍后我们会为您跳转到首页");
                    setTimeout( function(){
                        location.href = "index.html";
                    },2000)
                }
                if(res.type === "error"){
                    alert( res.msg );
                }
            }
        })
    }

})();